/**
 * Created by Administrator on 2017/8/24.
 */
import React, {Component} from 'react'
import { Nav, NavItem } from 'react-bootstrap'
import {connect} from 'react-redux'
import {navigationsGet} from '../action/actions'
@connect(state => {
  return {
    items: state.navigationsReducer.items || []
  }
}, {
  navigationsGet
})
export default class TopNav extends Component {
  static propTypes = {
    items: React.PropTypes.array.isRequired,
    navigationsGet: React.PropTypes.func
  }
  constructor(props) {
    super(props)
    this.state = {
      selectItem: 1001
    }
    this.handleSelect = this.handleSelect.bind(this)
  }
  componentDidMount() {
    this.props.navigationsGet()
    console.log(this.props.items)
  }
  handleSelect(eventkey) {
    this.setState({selectItem: eventkey})
  }
  render() {
    return (
      <Nav bsStyle='tabs' activeKey={this.state.selectItem} onSelect={this.handleSelect}>
        {
          this.props.items.map((item) => {
            return <NavItem key={item.id} eventKey={item.id} >{item.title}</NavItem>
          })
        }
      </Nav>
    )
  }
}
